package com.whx.yimixian;

import android.app.Application;
import android.text.TextUtils;

import com.umeng.message.IUmengRegisterCallback;
import com.umeng.message.PushAgent;
import com.umeng.socialize.Config;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;
import com.whx.yimixian.http.OkHttpClientUtils;
import com.whx.yimixian.utils.NetConnUtil;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobUser;

/**
 * Created by Administrator on 2016/10/11.
 * 进行初始化
 */
public class MyApp extends Application {
    public static boolean FLAG = false;


    @Override
    public void onCreate() {
        super.onCreate();
        OkHttpClientUtils.getOkHttpClientUtils(this);
        if (!NetConnUtil.isNetConnected(getApplicationContext())) {
            //Toast.makeText(getApplicationContext(), "请检查网络", Toast.LENGTH_SHORT).show();
        }
        Bmob.initialize(this, "3f852b9ada4de48a0ec5393a5ee82e40");
        OkHttpClientUtils okHttpClientUtils = OkHttpClientUtils.getOkHttpClientUtils(this);
        okHttpClientUtils.getOkHttpClient();
        //初始化
        UMShareAPI.get(this);
        //AppID,AppSecret
        PlatformConfig.setWeixin("wx967daebe835fbeac", "5bb696d9ccd75a38c8a0bfe0675559b3");
        PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad");
        PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
        //新浪微博的回调地址
        Config.REDIRECT_URL = "www.baidu.com";

        PushAgent mPushAgent = PushAgent.getInstance(this);
        //注册推送服务，每次调用register方法都会回调该接口
        mPushAgent.register(new IUmengRegisterCallback() {

            @Override
            public void onSuccess(String deviceToken) {
                //注册成功会返回 device token
            }

            @Override
            public void onFailure(String s, String s1) {

            }
        });
        BmobUser currentUser = BmobUser.getCurrentUser(getApplicationContext(), BmobUser.class);
        if (currentUser != null) {
            String username = currentUser.getUsername();
            if (!TextUtils.isEmpty(username)) {
                FLAG = true;
            }
        }
    }


}
